<template>
    <!-- 申请废弃对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" @close="cancel" width="500px"
        append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="140px">
            <el-form-item label="Root Cause" prop="waiveCause">
                <el-input v-model="form.waiveCause" type="textarea" placeholder="请输入废弃原因"></el-input>
            </el-form-item>
        </el-form>
        <el-form ref="form" :model="form" :rules="rules" label-width="140px">
            <el-form-item label="Corrective Action" prop="correctiveAction">
                <el-input v-model="form.correctiveAction" type="textarea" placeholder="请输入纠正措施"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import {approverWaiveOrder} from "@/api/business/waiveOrder";
export default {
    name: 'ApproverWaive',
    data() {
        return {
            title: "申请废弃",
            open: false,
            form: { bId: null, waiveCause: null,correctiveAction:null },
            // 表单校验
            rules: {
                correctiveAction: [
                    { required: true, message: "Corrective Action不能为空", trigger: "blur" }
                ],
                waiveCause: [
                    { required: true, message: "Root Cause不能为空", trigger: "blur" }
                ],
            }
        };
    },
    computed: {
    },
    watch: {
    },
    methods: {
        openLog(bid) {
            this.open = true
            this.form.bId=bid
        },
        reset(){
            this.form = { bId: null, waiveCause: null,correctiveAction:null };
            this.resetForm("form");
        },
        submitForm(){
            this.$refs["form"].validate(valid => {
                if (valid) {
                    console.log(this.form)
                    approverWaiveOrder(this.form.bId,this.form).then(response => {
                        this.$modal.msgSuccess(response.msg);
                        this.open = false;
                        this.reset();
                        // 刷新父页面
                        this.$emit('updateList');
                    });
                }
            });

        },
        cancel() {
            this.open = false;
            this.reset();
        },
    },
};
</script>

<style scoped></style>
